package com.study.javaOther.bishi;

import java.util.*;

/**
 * @ClassName: SearchDemo
 * @Description:
 * @author: 王胜
 * @date 2021/6/21
 * @Version: 1.0
 **/
public class SearchDemo {
    public static void main(String[] args) {

    }

    public static void depthFirstSearch(TreeNode data) {
        Stack<TreeNode> nodeStack = new Stack<TreeNode>();
        nodeStack.push(data);
        while (!nodeStack.isEmpty()) {
            TreeNode node = nodeStack.pop();
            System.out.println(node.getNodeName());
            //获取节点的子节点
            TreeNode[] childrenNodes = node.getChildrenNodes();
            if (childrenNodes != null && childrenNodes.length > 0) {
                nodeStack.addAll(Arrays.asList(childrenNodes));
            }
        }
    }

    public static void breadthFirstSearch(TreeNode data) {
        Deque<TreeNode> nodeDeque = new ArrayDeque<>();
        nodeDeque.push(data);
        while (!nodeDeque.isEmpty()) {
            TreeNode node = nodeDeque.pollFirst();
            System.out.println(node.getNodeName());
            //获取节点的子节点
            List<TreeNode> treeNodes = Arrays.asList(node.getChildrenNodes());
            for (TreeNode treeNode : treeNodes) {
                nodeDeque.add(treeNode);
            }
        }
    }
}
